package com.shujia.control;

import com.shujia.service.ServiceDemo;
import com.shujia.service.impl.ServiceDemoImpl2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

@RestController
//@Controller
//@ResponseBody
@RequestMapping("controller")
public class ControllerDemo {

    @RequestMapping("hello")
    public String printHello(){
        System.out.println("**************************");
        System.out.println("printHello方法已经被调用");
        System.out.println("**************************");

        return "请求映射到printHello方法，并返回信息....";
    }

//    @RequestMapping("data")
//    public String getData(){
//        ServiceDemo serviceDemo = new ServiceDemo();
//        return serviceDemo.getServiceRes();
//    }

    @Autowired
    ServiceDemo serviceDemo;

    @Autowired
    ServiceDemo serviceDemo2;

    @RequestMapping("service")
    public String getServiceData(){
        return serviceDemo.getServiceRes();
    }

    @RequestMapping("service2")
    public String getServiceData2(){
        return serviceDemo2.getServiceRes();
    }


    @RequestMapping("select")
    public String getMysqlData(){
        return serviceDemo2.getDaoData();
    }


    @RequestMapping("time")
    public String getTime(){
        // 不符合Springboot中的规则，所有的对象由Springboot统一管理放至容器中
        Calendar instance = Calendar.getInstance();
        return instance.getTime().toString();
    }

    @Autowired
    Calendar calendar; // 从容器中获取Calendar类的对象

    @RequestMapping("time2")
    public String getTime2(){
        return calendar.getTime().toString();
    }

}
